{$R-}

(*
	breakSPort(port number, trueOrFalse) -- Send or clear a break on the serial port.
	By Harry Chesley.  DO NOT call the author!  Contact Apple Developer 
	Support on AppleLink "MacDTS" or on MCI "MacTech".

	ŠApple Computer, Inc. 1987
	All Rights Reserved.

	To compile and link this file using Macintosh Programmer's Workshop,

	pascal -w breakSPort.p
	link -m ENTRYPOINT -o HyperTerm -rt XCMD=1 -sn Main=breakSPort breakSPort.p.o "{MPW}"Libraries:interface.o
	
*)

{$S breakSPort } 	{ Segment name must be the same as the command name. }

unit DummyUnit;

interface

uses MemTypes, QuickDraw, OSIntf, HyperXCmd;

procedure EntryPoint(paramPtr: XCmdPtr);
	
implementation

type

Str31 = String[31];

procedure breakSPort(paramPtr: XCmdPtr); forward;

procedure EntryPoint(paramPtr: XCmdPtr);

	begin
		breakSPort(paramPtr);
	end;

procedure breakSPort(paramPtr: XCmdPtr);

	var portNumber: integer;
		setting: integer;
		outPort: integer;
		str: Str255;
		doBreak: boolean;

	{$I XCmdGlue.inc}

	procedure Fail(errMsg: Str255); { set theResult and quit }
		begin
			paramPtr^.returnValue := PasToZero(errMsg);
			exit(breakSPort);
		end;

	begin
		if paramPtr^.paramCount <> 2 then Fail('parameter count is not 2');

		ZeroToPas(paramPtr^.params[1]^,str);		{ First parameter is port number. }
		portNumber := StrToNum(str);
		if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
		ZeroToPas(paramPtr^.params[2]^,str);		{ Second parameter is setting. }
		doBreak := false;
		if length(str) > 0 then
			if (str[1] = 't') or (str[1] = 'T') then doBreak := true;

		if portNumber = 1 then outPort := -7
		else outPort := -9;
		if doBreak then
			begin
				if SerSetBrk(outPort) <> noErr then Fail('SerSetBrk failed');
			end
		else
			begin
				if SerClrBrk(outPort) <> noErr then Fail('SerClrBrk failed');
			end;
	end;

end.
